<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>继承</title>
</head>
<body>
    <script>
        //1.让爷爷拉二胡，爸爸弹琴
        function Grand() { }
        function Parent() { }
        Grand.prototype.tskill = '拉二胡';

        var grand = new Grand();
        function f() { }

        f.prototype = grand
        Parent.prototype = new f();
        
        var parent = new Parent();
        Parent.prototype.tskill = '弹琴';

        console.log(grand.tskill);
        console.log(parent.tskill);

        ///////////
        //分别使用call，apply为obj添加name，age属性
        function Test(name, age) {
          this.name = name;
          this.age = age;
        }
    
    
        obj = {
    
        }
        //    Test.call(obj);
        //    Test.apply(obj);
    
        obj = Test.bind(obj);
        console.log(obj);
        /////////////
        //实现陈鹏买车，其中有sayHi方法，功能:打印'陈鹏买了一辆红色的2.0宝马车'
        function Buycar(name) {
          this.name = name;
          this.sayHi = function () {
            console.log(this.name + '买了一辆红色的2.0宝马车');
          }
        }
        var aaa = new Buycar('陈鹏');
        aaa.sayHi();
        //////////////
        //父类Shape （属性有:name,length,width,方法有:Intro 我是XX形）
        //子类： Circle(属性有:r)
        //分别使用 原型链继承 构造函数继承 圣杯继承
        //原型链继承
        // function Shape(name, length, width) {
        //   this.name = name;
        //   this.length = length;
        //   this.width = width;
        //   this.Intro = function () {
        //     console.log('我是' + name + '形');
        //   }
        // }
        // function Circle(r) {
        //   this.r = r;
        // }
        // var shape = new Shape();
        // var circle = new Circle();
        // circle.prototype = shape;
        // Circle.prototype.r = '直径'
        // console.log(circle.prototype);
        //构造函数继承
        // function Shape(name, length, width) {
        //   this.name = name;
        //   this.length = length;
        //   this.width = width;
        //   this.Intro = function () {
        //     console.log('我是' + name + '形');
        //   }
        // }
        // function Circle(r, name) {
        //   Shape.call(this, name);
        //   this.r = r;
        // }
        // var circle = new Circle(2, '圆形')
        // console.log(circle.r);
        //圣杯继承
        function Shape(name, length, width) {
          this.name = name;
          this.length = length;
          this.width = width;
          this.Intro = function () {
            console.log('我是' + name + '形');
          }
        }
        function Circle(r) {
          this.r = r;
        }
        function inherit(Target, Origin) {
          function f() { }
          f.prototype = Origin.prototype;
          Target.prototype = new f();
          Target.prototype.constructor = Target;
        }
        inherit(Circle, Shape);
        var circle = new Circle();
        console.log(circle);
    
      </script>
</body>
</html>